package com.health.fragment.focusgroup;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.health.FWMYDPJActivity;
import com.health.NovaApplication;
import com.health.PersonalFileActivity.onFragmentSave;
import com.health.R;
import com.health.adapter.CheckBoxAdapter;
import com.health.adapter.RadioButtonAdapter;
import com.health.db.FDbManager;
import com.health.focusgroup.JSJBctivity;
import com.health.fragment.NovaFragment;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.CD_DRUGCONDITION;
import com.health.tablebean.CD_MENTALDISEASE_FOLLOWUP;
import com.health.tools.GlobalConts;
import com.health.view.spinner.NiceSpinner;
import com.health.widget.EditTextWithDate;
import com.health.widget.MyGridView;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.RadioButton;

/**
 * 重点人群-- 精神疾病---随访
 */
public class JSJB_SFXXFragment extends NovaFragment implements onFragmentSave {
    private static final String TAG = "JSJB_SFXXFragment";
    private View cqsf2View = null;
    private FDbManager fdbmanger = null;

    // ------------------------------基本信息-----------------------------
    private EditText ed_xm;
    private EditText ed_idcard;

    // ------------随访形式
    private RadioButton rbsfxs1, rbsfxs2, rbsfxs3;
    private List<RadioButton> rbsfxss;
    // -------------失访原因
    private RadioButton rbsfyy1, rbsfyy2, rbsfyy3, rbsfyy4, rbsfyy5, rbsfyy6;
    private EditText etsfqt;
    private List<RadioButton> rbsfyys;
    // -------------------
    // ----------死亡----------
    // 死亡
    private EditTextWithDate ed_swrq;// 死亡日期
    private RadioButton rbsw1, rbsw2, rbsw3, rbsw4, rbsw5, rbsw6, rbsw7, rbsw8, rbsw9, rbsw10, rbsw11, rbsw12, rbsw13;
    private List<RadioButton> rbsws;
    private EditText swqt;// 死亡其他
    // -------------------------
    private NiceSpinner nice_spinner_wxx;// 危险性
    private NiceSpinner nice_spinner_zzl;// 自知力
    private NiceSpinner nice_spinner_smqk;// 睡眠情况
    private NiceSpinner nice_spinner_ysqk;// 饮食情况
    private NiceSpinner nice_spinner_grshll;// 个人生活料理
    private NiceSpinner nice_spinner_jwld;// 家务劳动
    private NiceSpinner nice_spinner_scldjgz;// 生产劳动及工作
    private NiceSpinner nice_spinner_xxnl;// 学习能力
    private NiceSpinner nice_spinner_shrjjw;// 社会人际交往
    private NiceSpinner nice_spinner_gszk;// 关锁状况
    private NiceSpinner nice_spinner_zyqk;// 住院情况
    private NiceSpinner nice_spinner_fyycx;// 服药依从性
    private NiceSpinner nice_spinner_zlxg;// 治疗效果
    private NiceSpinner nice_spinner_sffl;// 随访分类

    private MyGridView gd_mqzz;// 目前症状
    private MyGridView gd_sysjc;// 实验室检查
    private MyGridView gd_ywblfy;// 药物不良反应
    private MyGridView gd_sfzz;// 是否转诊
    private MyGridView gd_kfcs;// 康复

    // 用药情况
    private EditText ed_yw1;
    private EditText ed_yw1_mr;
    private EditText ed_yw1_mcjl;
    private EditText ed_yw2;
    private EditText ed_yw2_mr;
    private EditText ed_yw2_mcjl;
    private EditText ed_yw3;
    private EditText ed_yw3_mr;
    private EditText ed_yw3_mcjl;
    // 用药指导
    private EditText ed_ywzd1;
    private EditText ed_ywzd1_mr;
    private EditText ed_ywzd1_mcjl;
    private EditText ed_ywzd2;
    private EditText ed_ywzd2_mr;
    private EditText ed_ywzd2_mcjl;
    private EditText ed_ywzd3;
    private EditText ed_ywzd3_mr;
    private EditText ed_ywzd3_mcjl;

    private EditTextWithDate ed_sfsj;
    private EditTextWithDate ed_mccysj;
    private EditTextWithDate ed_xcsfrq;
    private NiceSpinner ed_sfys;// 随访医生
    private NiceSpinner nice_spinner_dw1;// 药物单位1
    private NiceSpinner nice_spinner_dw2;// 药物单位2
    private NiceSpinner nice_spinner_dw3;// 药物单位3
    private NiceSpinner nice_spinner_dw4;// 药物单位4
    private NiceSpinner nice_spinner_dw5;// 药物单位5
    private NiceSpinner nice_spinner_dw6;// 药物单位6
    private EditText ed_sh_qdzs;
    private EditText ed_sh_zs;
    private EditText ed_sh_zh;
    private EditText ed_sh_zs4;
    private EditText ed_sh_zsws;

    private EditText ed_zzzjgks;
    // ----------------------------------------------------------------------
    private RadioButtonAdapter adapter_sysjc = null;
    private RadioButtonAdapter adapter_ywblfy = null;
    private RadioButtonAdapter adapter_sfzz = null;
    private CheckBoxAdapter adapter_mqzz = null;
    private CheckBoxAdapter adapter_kfcs = null;
    private List<BD_DD_INFO> lst_wxx = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> lst_zzl = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> lst_smqk = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> lst_ysqk = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> lst_grshll = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> lst_jwld = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> lst_scldjgz = new ArrayList<BD_DD_INFO>();

    private List<BD_DD_INFO> lst_xxnl = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> lst_shrjjw = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> lst_gszk = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> lst_zyqk = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> lst_fyycx = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> lst_zlxg = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> lst_sffl = new ArrayList<BD_DD_INFO>();

    private List<BD_DD_INFO> lst_bcsfxs = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> lst_rsfyy = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> lst_swyyqtjb = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> ywdw_list = new ArrayList<BD_DD_INFO>();

    private String str_sysjcId = "";
    private String str_sysjcContent = "";
    private String str_sfzzId = "";
    private String str_sfzzContent = "";
    private String str_ywblfyContent = "";
    private String str_ywblfyId = "";

    private String str_mqzzContent = "";
    private String str_mqzzId = "";
    private String str_kfcsContent = "";
    private String str_kfcsId = "";

    public ARCHIVE_BASEINFO userInfo;
    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    private int from_followup = -1;
    private int from_drug = -1;
    private int from_drug2 = -1;
    private int drug_id1 = -1;
    private int drug_id2 = -1;
    private int drug_id3 = -1;
    private int drug_id4 = -1;
    private int drug_id5 = -1;
    private int drug_id6 = -1;
    private CheckBox cb_nothing;

    private RadioButton rb_wu;
    private RadioButton rb_you;
    private EditText et_you;
    private RadioButton rb_xcbsy;
    private RadioButton rb_fou;
    private RadioButton rb_shi;
    private EditText et_zzyy;
    private EditText ed_sh_qtwhxw;

    String bcsfxsids[] = new String[]{"DM04-04_1", "DM04-04_2", "DM04-04_3"};
    String rsfyyIds[] = new String[]{"DM07-06_2", "DM07-06_3", "DM07-06_4", "DM07-06_5", "DM07-06_6", "DM07-06_1"};
    String swyyIds[] = new String[]{"DM01-67_14", "DM01-67_15", "DM01-67_16", "DM01-67_17", "DM01-67_18",
            "DM01-67_19", "DM01-67_20", "DM01-67_21", "DM01-67_22", "DM01-67_23", "DM01-67_24", "DM01-67_25",
            "DM01-67_26",};

    @Override
    public View findViews(LayoutInflater inflater) {
        fdbmanger = NovaApplication.fdbmanger;
        userInfo = NovaApplication.getUserInfo();
        cqsf2View = inflater.inflate(R.layout.jsjb_sfxx, null);
        initViews(cqsf2View);
        // 用药情况
        GlobalConts.setMaxLength(25, ed_yw1, ed_yw2, ed_yw3);
        GlobalConts.setMaxLength(3, ed_yw1_mr, ed_yw2_mr, ed_yw3_mr);
        GlobalConts.setMaxLength(6, ed_yw1_mcjl, ed_yw2_mcjl, ed_yw3_mcjl);
        // 用药指导
        GlobalConts.setMaxLength(25, ed_ywzd1, ed_ywzd2, ed_ywzd3);
        GlobalConts.setMaxLength(3, ed_ywzd1_mr, ed_ywzd2_mr, ed_ywzd3_mr);
        GlobalConts.setMaxLength(6, ed_ywzd1_mcjl, ed_ywzd2_mcjl, ed_ywzd3_mcjl);

        GlobalConts.setMaxLength(5, ed_sh_qdzs, ed_sh_zs, ed_sh_zh, ed_sh_zs4, ed_sh_zsws, ed_sh_qtwhxw);
        GlobalConts.setMaxLength(35, ed_zzzjgks);

        return cqsf2View;
    }

    /**
     * 初始化布局
     *
     * @param v
     * @author 王婷婷
     * @date 2015年12月21日 上午11:10:55
     */
    @SuppressWarnings("serial")
    private void initViews(View v) {
        ed_swrq = (EditTextWithDate) v.findViewById(R.id.ed_swrq);
        ed_swrq.setBefore(true);
        swqt = (EditText) v.findViewById(R.id.swqt);
        etsfqt = (EditText) v.findViewById(R.id.etsfqt);

        swqt.setVisibility(View.INVISIBLE);
        etsfqt.setVisibility(View.INVISIBLE);

        ed_xm = (EditText) v.findViewById(R.id.ed_xm);
        ed_idcard = (EditText) v.findViewById(R.id.ed_idcard);
        rbsfxs1 = (RadioButton) v.findViewById(R.id.rbsf1);
        rbsfxs2 = (RadioButton) v.findViewById(R.id.rbsf2);
        rbsfxs3 = (RadioButton) v.findViewById(R.id.rbsf3);
        rbsfyy1 = (RadioButton) v.findViewById(R.id.rbsfyy1);
        rbsfyy2 = (RadioButton) v.findViewById(R.id.rbsfyy2);
        rbsfyy3 = (RadioButton) v.findViewById(R.id.rbsfyy3);
        rbsfyy4 = (RadioButton) v.findViewById(R.id.rbsfyy4);
        rbsfyy5 = (RadioButton) v.findViewById(R.id.rbsfyy5);
        rbsfyy6 = (RadioButton) v.findViewById(R.id.rbsfyy6);
        rbsw1 = (RadioButton) v.findViewById(R.id.rbsw1);
        rbsw2 = (RadioButton) v.findViewById(R.id.rbsw2);
        rbsw3 = (RadioButton) v.findViewById(R.id.rbsw3);
        rbsw4 = (RadioButton) v.findViewById(R.id.rbsw4);
        rbsw5 = (RadioButton) v.findViewById(R.id.rbsw5);
        rbsw6 = (RadioButton) v.findViewById(R.id.rbsw6);
        rbsw7 = (RadioButton) v.findViewById(R.id.rbsw7);
        rbsw8 = (RadioButton) v.findViewById(R.id.rbsw8);
        rbsw9 = (RadioButton) v.findViewById(R.id.rbsw9);
        rbsw10 = (RadioButton) v.findViewById(R.id.rbsw10);
        rbsw11 = (RadioButton) v.findViewById(R.id.rbsw11);
        rbsw12 = (RadioButton) v.findViewById(R.id.rbsw12);
        rbsw13 = (RadioButton) v.findViewById(R.id.rbsw13);
        rbsfxss = new ArrayList<RadioButton>() {
            {
                add(rbsfxs1);
                add(rbsfxs2);
                add(rbsfxs3);
            }
        };
        rbsfyys = new ArrayList<RadioButton>() {
            {
                add(rbsfyy1);
                add(rbsfyy2);
                add(rbsfyy3);
                add(rbsfyy4);
                add(rbsfyy5);
                add(rbsfyy6);
            }
        };
        rbsws = new ArrayList<RadioButton>() {
            {
                add(rbsw1);
                add(rbsw2);
                add(rbsw3);
                add(rbsw4);
                add(rbsw5);
                add(rbsw6);
                add(rbsw7);
                add(rbsw8);
                add(rbsw9);
                add(rbsw10);
                add(rbsw11);
                add(rbsw12);
                add(rbsw13);
            }
        };
        ed_yw1 = (EditText) v.findViewById(R.id.ed_yw1);
        ed_yw1_mr = (EditText) v.findViewById(R.id.ed_yw1_mr);
        ed_yw1_mcjl = (EditText) v.findViewById(R.id.ed_yw1_mcjl);
        ed_yw2 = (EditText) v.findViewById(R.id.ed_yw2);
        ed_yw2_mr = (EditText) v.findViewById(R.id.ed_yw2_mr);
        ed_yw2_mcjl = (EditText) v.findViewById(R.id.ed_yw2_mcjl);
        ed_yw3 = (EditText) v.findViewById(R.id.ed_yw3);
        ed_yw3_mr = (EditText) v.findViewById(R.id.ed_yw3_mr);
        ed_yw3_mcjl = (EditText) v.findViewById(R.id.ed_yw3_mcjl);

        ed_ywzd1 = (EditText) v.findViewById(R.id.ed_ywzd1);
        ed_ywzd1_mr = (EditText) v.findViewById(R.id.ed_ywzd1_mr);
        ed_ywzd1_mcjl = (EditText) v.findViewById(R.id.ed_ywzd1_mcjl);
        ed_ywzd2 = (EditText) v.findViewById(R.id.ed_ywzd2);
        ed_ywzd2_mr = (EditText) v.findViewById(R.id.ed_ywzd2_mr);
        ed_ywzd2_mcjl = (EditText) v.findViewById(R.id.ed_ywzd2_mcjl);
        ed_ywzd3 = (EditText) v.findViewById(R.id.ed_ywzd3);
        ed_ywzd3_mr = (EditText) v.findViewById(R.id.ed_ywzd3_mr);
        ed_ywzd3_mcjl = (EditText) v.findViewById(R.id.ed_ywzd3_mcjl);

        ed_swrq = (EditTextWithDate) v.findViewById(R.id.ed_swrq);// 死亡日期

        nice_spinner_wxx = (NiceSpinner) v.findViewById(R.id.nice_spinner_wxx);
        nice_spinner_zzl = (NiceSpinner) v.findViewById(R.id.nice_spinner_zzl);
        nice_spinner_smqk = (NiceSpinner) v.findViewById(R.id.nice_spinner_smqk);
        nice_spinner_ysqk = (NiceSpinner) v.findViewById(R.id.nice_spinner_ysqk);
        nice_spinner_grshll = (NiceSpinner) v.findViewById(R.id.nice_spinner_grshll);
        nice_spinner_jwld = (NiceSpinner) v.findViewById(R.id.nice_spinner_jwld);
        nice_spinner_scldjgz = (NiceSpinner) v.findViewById(R.id.nice_spinner_scldjgz);

        nice_spinner_xxnl = (NiceSpinner) v.findViewById(R.id.nice_spinner_xxnl);
        nice_spinner_shrjjw = (NiceSpinner) v.findViewById(R.id.nice_spinner_shrjjw);
        nice_spinner_gszk = (NiceSpinner) v.findViewById(R.id.nice_spinner_gszk);
        nice_spinner_zyqk = (NiceSpinner) v.findViewById(R.id.nice_spinner_zyqk);
        nice_spinner_fyycx = (NiceSpinner) v.findViewById(R.id.nice_spinner_fyycx);
        nice_spinner_zlxg = (NiceSpinner) v.findViewById(R.id.nice_spinner_zlxg);
        nice_spinner_sffl = (NiceSpinner) v.findViewById(R.id.nice_spinner_sffl);

        gd_mqzz = (MyGridView) v.findViewById(R.id.gd_mqzz);
        gd_sysjc = (MyGridView) v.findViewById(R.id.gd_sysjc);
        gd_ywblfy = (MyGridView) v.findViewById(R.id.gd_ywblfy);
        gd_sfzz = (MyGridView) v.findViewById(R.id.gd_zz);
        gd_kfcs = (MyGridView) v.findViewById(R.id.gd_kfcs);

        ed_sfsj = (EditTextWithDate) v.findViewById(R.id.ed_sfsj);
        ed_mccysj = (EditTextWithDate) v.findViewById(R.id.ed_mccysj);
        ed_xcsfrq = (EditTextWithDate) v.findViewById(R.id.ed_xcsfrq);
        ed_sfys = (NiceSpinner) v.findViewById(R.id.ed_sfys);
        ed_sfsj.setBefore(true);
        ed_xcsfrq.setAfter(true);
        ed_sh_qdzs = (EditText) v.findViewById(R.id.ed_sh_qdzs);
        ed_sh_zs = (EditText) v.findViewById(R.id.ed_sh_zs);
        ed_sh_zh = (EditText) v.findViewById(R.id.ed_sh_zh);
        ed_sh_zs4 = (EditText) v.findViewById(R.id.ed_sh_zs4);
        ed_sh_zsws = (EditText) v.findViewById(R.id.ed_sh_zsws);
        cb_nothing = (CheckBox) v.findViewById(R.id.cb_nothing);
        ed_zzzjgks = (EditText) v.findViewById(R.id.ed_zzzjgks);
        GlobalConts.doctorList(ed_sfys);
        ed_swrq.setText("");
        ed_swrq.showDialog(false);
        for (RadioButton rb : rbsws) {
            rb.setEnabled(false);
            rb.setChecked(false);
        }

        rb_wu = (RadioButton) v.findViewById(R.id.rb_wu);
        rb_you = (RadioButton) v.findViewById(R.id.rb_you);
        et_you = (EditText) v.findViewById(R.id.et_you);
        rb_xcbsy = (RadioButton) v.findViewById(R.id.rb_xcbsy);
        rb_fou = (RadioButton) v.findViewById(R.id.rb_fou);
        rb_shi = (RadioButton) v.findViewById(R.id.rb_shi);
        et_zzyy = (EditText) v.findViewById(R.id.et_zzyy);
        ed_sh_qtwhxw = (EditText) v.findViewById(R.id.ed_sh_qtwhxw);
        nice_spinner_dw1 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw1);
        nice_spinner_dw2 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw2);
        nice_spinner_dw3 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw3);
        nice_spinner_dw4 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw4);
        nice_spinner_dw5 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw5);
        nice_spinner_dw6 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw6);

    }

    /**
     * 绑定数据值
     *
     * @param str_where
     * @param flag
     * @author 王婷婷
     * @date 2015年12月17日 上午10:30:30
     */
    private void bindDdata(String flag, String str_where) {
        List<BD_DD_INFO> listZZs = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, str_where);

        if (flag.equals("症状")) {

            adapter_mqzz = new CheckBoxAdapter(getActivity(), listZZs);
            adapter_mqzz.setOtherMaxLength(50);
            gd_mqzz.setAdapter(adapter_mqzz);
        } else if (flag.equals("康复")) {
            List<BD_DD_INFO> list = new ArrayList<>();
            for (int i = 0; i < listZZs.size(); i++) {
                if (i == 0) {
                    list.add(listZZs.get(1));
                } else if (i == 1) {
                    list.add(listZZs.get(0));
                } else {
                    list.add(listZZs.get(i));
                }
            }
            adapter_kfcs = new CheckBoxAdapter(getActivity(), list);
            gd_kfcs.setAdapter(adapter_kfcs);
        } else if (flag.equals("有无")) {
            adapter_sysjc = new RadioButtonAdapter(listZZs, getActivity());
            gd_sysjc.setAdapter(adapter_sysjc);

            adapter_ywblfy = new RadioButtonAdapter(listZZs, getActivity());
            gd_ywblfy.setAdapter(adapter_ywblfy);
        } else if (flag.equals("是否转诊")) {
            adapter_sfzz = new RadioButtonAdapter(listZZs, getActivity());
            gd_sfzz.setAdapter(adapter_sfzz);
        }
    }

    /**
     * 绑定数据值
     *
     * @param str_where
     * @param flag
     * @author 王婷婷
     * @date 2015年12月17日 上午10:30:30
     */
    private void bindSpinnerdata(String flag, String str_where) {
        List<BD_DD_INFO> listZZs = new ArrayList<BD_DD_INFO>();
        BD_DD_INFO bd = new BD_DD_INFO();
        bd.setDATAINFO("请选择");
        bd.setID("");
        listZZs.add(bd);

        List<BD_DD_INFO> sList1 = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
                str_where + " order by cast(SORT as int) asc");
        listZZs.addAll(sList1);

        if (flag.equals("危险性")) {
            lst_wxx = listZZs;
            nice_spinner_wxx.attachDataSource(lst_wxx);

        } else if (flag.equals("自知力")) {
            lst_zzl = listZZs;
            nice_spinner_zzl.attachDataSource(lst_zzl);
        } else if (flag.equals("睡眠情况")) {

            int size = listZZs.size();
            if (size > 0) {
                lst_smqk = new ArrayList<BD_DD_INFO>();
                lst_ysqk = new ArrayList<BD_DD_INFO>();
                lst_grshll = new ArrayList<BD_DD_INFO>();
                lst_jwld = new ArrayList<BD_DD_INFO>();
                lst_xxnl = new ArrayList<BD_DD_INFO>();
                lst_shrjjw = new ArrayList<BD_DD_INFO>();
                for (int i = 0; i < size; i++) {
                    String str_id = listZZs.get(i).getID();
                    if (str_id.equals("DM01-69_5")) {
                        lst_scldjgz.add(listZZs.get(i));
                    }
                    if (str_id.equals("DM01-69_1") || str_id.equals("DM01-69_2") || str_id.equals("DM01-69_4")
                            || str_id.equals("")) {
                        lst_smqk.add(listZZs.get(i));
                        lst_ysqk.add(listZZs.get(i));
                        lst_grshll.add(listZZs.get(i));
                        lst_jwld.add(listZZs.get(i));
                        lst_xxnl.add(listZZs.get(i));
                        lst_shrjjw.add(listZZs.get(i));
                        lst_scldjgz.add(listZZs.get(i));
                    }
                }
            }
            nice_spinner_smqk.attachDataSource(lst_smqk);
            nice_spinner_ysqk.attachDataSource(lst_ysqk);
            nice_spinner_grshll.attachDataSource(lst_grshll);
            nice_spinner_jwld.attachDataSource(lst_jwld);
            nice_spinner_scldjgz.attachDataSource(lst_scldjgz);
            nice_spinner_xxnl.attachDataSource(lst_xxnl);
            nice_spinner_shrjjw.attachDataSource(lst_shrjjw);
        } else if (flag.equals("关锁")) {
            lst_gszk = listZZs;
            nice_spinner_gszk.attachDataSource(lst_gszk);
        } else if (flag.equals("住院")) {
            lst_zyqk = listZZs;
            nice_spinner_zyqk.attachDataSource(lst_zyqk);
        } else if (flag.equals("服药依从性")) {
            lst_fyycx = listZZs;
            nice_spinner_fyycx.attachDataSource(lst_fyycx);
        } else if (flag.equals("治疗效果")) {
            lst_zlxg = listZZs;
            List<BD_DD_INFO> list = fdbmanger.findAllInInfoDB(BD_DD_INFO.class);
            for (int i = 0; i < list.size(); i++) {
                String str_id = list.get(i).getID();
                if (str_id.equals("DM01-69_5")) {
                    lst_zlxg.add(list.get(i));
                }
            }
            nice_spinner_zlxg.attachDataSource(lst_zlxg);
        } else if (flag.equals("随访分类")) {
            int size = listZZs.size();
            if (size > 0) {
                lst_sffl = new ArrayList<BD_DD_INFO>();
                for (int i = 0; i < size; i++) {
                    String str_id = listZZs.get(i).getID();
                    if (str_id.equals("DM01-71_5") || str_id.equals("DM01-71_6") || str_id.equals("DM01-71_7")
                            || str_id.equals("")) {// ||
                        // str_id.equals("DM01-71_8")
                        lst_sffl.add(listZZs.get(i));
                    }
                }
            }

            nice_spinner_sffl.attachDataSource(lst_sffl);
        } else if (flag.equals("药物单位")) {
            ywdw_list = sList1;
            nice_spinner_dw1.attachDataSource(sList1);
            nice_spinner_dw2.attachDataSource(sList1);
            nice_spinner_dw3.attachDataSource(sList1);
            nice_spinner_dw4.attachDataSource(sList1);
            nice_spinner_dw5.attachDataSource(sList1);
            nice_spinner_dw6.attachDataSource(sList1);
        }
    }

    @Override
    public void setupView(View view) {

    }

    /**
     * 死亡原因点击事件
     */
    OnCheckedChangeListener swoccl = new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                int buttonId = buttonView.getId();
                for (RadioButton rb : rbsws) {
                    if (rb.getId() != buttonId) {
                        rb.setChecked(false);
                    }
                }
                if (R.id.rbsw13 == buttonView.getId()) {
                    swqt.setText("");
                    swqt.setVisibility(View.VISIBLE);
                }
            } else {
                if (R.id.rbsw13 == buttonView.getId()) {
                    swqt.setText("");
                    swqt.setVisibility(View.INVISIBLE);
                }
            }
        }
    };
    /**
     * 失访选择事件
     */
    OnCheckedChangeListener sfoccl = new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                int buttonId = buttonView.getId();
                for (RadioButton rb : rbsfxss) {
                    if (rb.getId() != buttonId) {
                        rb.setChecked(false);
                    }
                }
            }
        }
    };
    /**
     * 失访原因选择事件
     */
    OnCheckedChangeListener sfyyoccl = new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                int buttonId = buttonView.getId();
                for (RadioButton rb : rbsfyys) {
                    if (rb.getId() != buttonId) {
                        rb.setChecked(false);
                    }
                }
                if (R.id.rbsfyy5 == buttonView.getId()) {
                    etsfqt.setText("");
                    etsfqt.setVisibility(View.VISIBLE);
                } else if (R.id.rbsfyy6 == buttonView.getId()) {
                    ed_swrq.setText("");
                    ed_swrq.showDialog(true);
                    for (RadioButton rb : rbsws) {
                        rb.setEnabled(true);
                        rb.setChecked(false);
                    }
                }
            } else {
                if (R.id.rbsfyy5 == buttonView.getId()) {
                    etsfqt.setText("");
                    etsfqt.setVisibility(View.INVISIBLE);
                } else if (R.id.rbsfyy6 == buttonView.getId()) {
                    ed_swrq.setText("");
                    ed_swrq.showDialog(false);
                    for (RadioButton rb : rbsws) {
                        rb.setEnabled(false);
                        rb.setChecked(false);
                    }
                }
            }
        }
    };

    @Override
    public void addListener() {
        for (RadioButton rb : rbsfxss) {
            rb.setOnCheckedChangeListener(sfoccl);
        }
        for (RadioButton rb : rbsfyys) {
            rb.setOnCheckedChangeListener(sfyyoccl);
        }
        for (RadioButton rb : rbsws) {
            rb.setOnCheckedChangeListener(swoccl);
        }
        cb_nothing.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    ed_sh_qdzs.setText("");
                    ed_sh_qdzs.setFocusable(false);
                    ed_sh_qdzs.setFocusableInTouchMode(false);

                    ed_sh_zs.setText("");
                    ed_sh_zs.setFocusable(false);
                    ed_sh_zs.setFocusableInTouchMode(false);

                    ed_sh_zh.setText("");
                    ed_sh_zh.setFocusable(false);
                    ed_sh_zh.setFocusableInTouchMode(false);

                    ed_sh_zs4.setText("");
                    ed_sh_zs4.setFocusable(false);
                    ed_sh_zs4.setFocusableInTouchMode(false);

                    ed_sh_zsws.setText("");
                    ed_sh_zsws.setFocusable(false);
                    ed_sh_zsws.setFocusableInTouchMode(false);

                    ed_sh_qtwhxw.setText("");
                    ed_sh_qtwhxw.setFocusable(false);
                    ed_sh_qtwhxw.setFocusableInTouchMode(false);
                } else {
                    ed_sh_qdzs.setFocusable(true);
                    ed_sh_qdzs.setFocusableInTouchMode(true);

                    ed_sh_zs.setFocusable(true);
                    ed_sh_zs.setFocusableInTouchMode(true);

                    ed_sh_zh.setFocusable(true);
                    ed_sh_zh.setFocusableInTouchMode(true);

                    ed_sh_zs4.setFocusable(true);
                    ed_sh_zs4.setFocusableInTouchMode(true);

                    ed_sh_zsws.setFocusable(true);
                    ed_sh_zsws.setFocusableInTouchMode(true);

                    ed_sh_qtwhxw.setFocusable(true);
                    ed_sh_qtwhxw.setFocusableInTouchMode(true);
                }
            }
        });
        rb_fou.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    et_zzyy.setEnabled(false);
                    et_zzyy.setText("");
                }

            }
        });

        rb_shi.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    et_zzyy.setEnabled(true);
                }

            }
        });

        rb_wu.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    et_you.setEnabled(false);
                    et_you.setText("");
                }

            }
        });

        rb_you.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    et_you.setEnabled(true);
                }

            }
        });

    }

    @Override
    public void setData() {
        bindDdata("症状", "PARENTID='DM07-01'");
        bindDdata("康复", "PARENTID='DM07-03'");
        bindDdata("有无", "PARENTID='DM01-11'");
        bindDdata("是否转诊", "PARENTID='DM01-10'");
        bindSpinnerdata("危险性", "PARENTID='DM07-02'");
        bindSpinnerdata("自知力", "PARENTID='DM01-74'");
        bindSpinnerdata("睡眠情况", "PARENTID='DM01-69'");
        bindSpinnerdata("饮食情况", "PARENTID='DM01-69'");// 个人生活情况、学习能力、社会人际交往
        bindSpinnerdata("关锁", "PARENTID='DM01-75'");
        bindSpinnerdata("住院", "PARENTID='DM01-76'");
        bindSpinnerdata("服药依从性", "PARENTID='DM01-70'");
        bindSpinnerdata("治疗效果", "PARENTID='DM01-77'");
        bindSpinnerdata("随访分类", "PARENTID='DM01-71'");
        bindSpinnerdata("药物单位", "PARENTID='DM04-05'");
        setData_followUP();
        setData_drug();
    }

    @Override
    public void save() {

        // 危险性
        String str_lst_wxx = lst_wxx.get(nice_spinner_wxx.getSelectedIndex()).getID();
        Log.w(TAG, "危险性" + str_lst_wxx);
        if (TextUtils.isEmpty(str_lst_wxx)) {
            nice_spinner_wxx.setBackgroundColor(Color.YELLOW);
            ((JSJBctivity) getActivity()).showTextDialog("请选择危险性");
            return;
        } else {
            nice_spinner_wxx.setBackgroundColor(Color.WHITE);
        }

        // 目前症状
        String str_zz = adapter_mqzz.getCheckedIdsStr();
        if (TextUtils.isEmpty(str_zz)) {
            gd_mqzz.setBackgroundColor(Color.YELLOW);
            ((JSJBctivity) getActivity()).showTextDialog("请选择目前症状");
            return;
        } else {
            gd_mqzz.setBackgroundColor(Color.WHITE);
        }

        // 下次随访时间
        String str_xcsfsj = ed_xcsfrq.getText().toString();
        if (TextUtils.isEmpty(str_xcsfsj)) {
            ed_xcsfrq.setBackgroundColor(Color.YELLOW);
            ((JSJBctivity) getActivity()).showTextDialog("请选择下次随访日期");
            return;
        } else {
            ed_xcsfrq.setBackgroundColor(Color.WHITE);
        }
        getRadioButtonCheckedData();
        getCheckBoxedData();
        saveData_followup();
        saveDrug();
    }

    /**
     * 获取转诊的信息
     *
     * @author 王婷婷
     * @date 2015年12月16日 下午3:10:48
     */
    private void getRadioButtonCheckedData() {
        str_sysjcId = adapter_sysjc.getChecked();
        str_sysjcContent = adapter_sysjc.getCheckedOther();
        str_sfzzId = adapter_sfzz.getChecked();
        str_sfzzContent = adapter_sfzz.getCheckedOther();

        str_ywblfyContent = adapter_ywblfy.getCheckedOther();
        str_ywblfyId = adapter_ywblfy.getChecked();

        if (rb_wu.isChecked()) {
            str_ywblfyId = "DM01-11_1";
        } else if (rb_you.isChecked()) {
            str_ywblfyId = "DM01-11_2";
        } else if (rb_xcbsy.isChecked()) {
            str_ywblfyId = "DM01-69_5";// TODO 此项不适用
        }

        if (!TextUtils.isEmpty(et_you.getText())) {
            str_ywblfyContent = et_you.getText().toString();
        }

        if (rb_fou.isChecked()) {
            str_sfzzId = "DM01-10_1";
        } else if (rb_shi.isChecked()) {
            str_sfzzId = "DM01-10_2";
        }
        if (!TextUtils.isEmpty(et_zzyy.getText())) {
            str_sfzzContent = et_zzyy.getText().toString();
        }

    }

    /**
     * 获取 被选中的checkbox
     *
     * @author 王婷婷
     * @date 2015年12月19日 上午11:34:30
     */
    private void getCheckBoxedData() {

        str_mqzzId = adapter_mqzz.getCheckedIdsStr();
        str_mqzzContent = adapter_mqzz.getOther();
        str_kfcsId = adapter_kfcs.getCheckedIdsStr();
        str_kfcsContent = adapter_kfcs.getOther();

    }

    /**
     * 保存数据
     *
     * @author 王婷婷
     * @date 2015年12月17日 上午11:13:39
     */
    private void saveData_followup() {

        CD_MENTALDISEASE_FOLLOWUP ques = new CD_MENTALDISEASE_FOLLOWUP();

        ques.setIDCARD(userInfo.getIDCARD());
        // ques.setARCHIVEID(userInfo.getARCHIVEID());// 设置档案编号

        // 本次随访形式
        int i = -1;
        for (RadioButton rb : rbsfxss) {
            i += 1;
            if (rb.isChecked()) {
                break;
            }
        }
        ques.setFOLLOWUP_TYPE(i == -1 ? "" : bcsfxsids[i]);
        // 若失访，原因
        i = -1;
        for (RadioButton rb : rbsfyys) {
            i += 1;
            if (rb.isChecked()) {
                break;
            }
        }
        ques.setLossFollow(i == -1 ? "" : rsfyyIds[i]);
        // if (!TextUtils.isEmpty(etsfqt.getText())) {
        ques.setLossFollow_EX(etsfqt.getText().toString());
        // }
        // 死亡日期
        // if (!TextUtils.isEmpty(ed_swrq.getText())) {
        ques.setDeathDate(ed_swrq.getDate());
        // }else{
        // }
        // 死亡原因
        i = -1;
        for (RadioButton rb : rbsws) {
            i += 1;
            if (rb.isChecked()) {
                break;
            }
        }
        ques.setDeathCause(i == -1 ? "" : swyyIds[i]);
        // if (!TextUtils.isEmpty(swqt.getText())) {
        ques.setDeathCause_EX(swqt.getText().toString());
        // }
        //
        String str_ed_time1_next = ed_xcsfrq.getText().toString();
        if (!TextUtils.isEmpty(str_ed_time1_next)) {
            try {
                ques.setNEXTFOLLOWUP_DATE((Date) dateFormat.parse(str_ed_time1_next));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        } else {
            ques.setNEXTFOLLOWUP_DATE(null);
        }
        ques.setFOLLOWUPDOCTOR(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
        ques.setIS_DEL("N");
        String str_ed_time_followdate = ed_sfsj.getText().toString();
        if (!TextUtils.isEmpty(str_ed_time_followdate)) {
            try {
                ques.setFOLLOWUP_DATE((Date) dateFormat.parse(str_ed_time_followdate));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        } else {
            ques.setFOLLOWUP_DATE(null);
        }

        ques.setFATALNESS(lst_wxx.get(nice_spinner_wxx.getSelectedIndex()).getID());
        ques.setPRESENT_SYMPTOM(str_mqzzId);
        ques.setPRESENT_SYMPTO_OTHER(str_mqzzContent);

        ques.setINSIGHT(lst_zzl.get(nice_spinner_zzl.getSelectedIndex()).getID());
        ques.setSLEEP_QUALITY(lst_smqk.get(nice_spinner_smqk.getSelectedIndex()).getID());
        ques.setDIET(lst_ysqk.get(nice_spinner_ysqk.getSelectedIndex()).getID());
        ques.setPERSONAL_CARE(lst_grshll.get(nice_spinner_grshll.getSelectedIndex()).getID());
        ques.setHOUSEWORK(lst_jwld.get(nice_spinner_jwld.getSelectedIndex()).getID());
        ques.setPRODUCT_LABOR_WORK(lst_scldjgz.get(nice_spinner_scldjgz.getSelectedIndex()).getID());

        ques.setLEARNING_ABILITY(lst_xxnl.get(nice_spinner_xxnl.getSelectedIndex()).getID());
        ques.setSOCIAL_INTER_INTERA(lst_shrjjw.get(nice_spinner_shrjjw.getSelectedIndex()).getID());

        // 1轻度滋事

        ques.setMILD_TROUBLE_FREQUEN(ed_sh_qdzs.getText().toString());
        // 2肇事

        ques.setCREATE_DISTU_FREQUEN(ed_sh_zs.getText().toString());

        // 3肇祸

        ques.setCAUSE_ACCID_FREQUEN(ed_sh_zh.getText().toString());

        // 4自伤

        ques.setAUTOLESION_FREQUEN(ed_sh_zs4.getText().toString());

        // 5自杀未遂

        ques.setATTEMPT_SUIC_FREQUEN(ed_sh_zsws.getText().toString());
        // 其他危害行为

        if (!TextUtils.isEmpty(ed_sh_qtwhxw.getText())) {
            ques.setOtherDamage_FREQUEN(Integer.valueOf(ed_sh_qtwhxw.getText().toString()));
        }

        if (cb_nothing.isChecked()) {
            ques.setATTEMPT_SUICIDE_NONE("null");
        } else {
            ques.setATTEMPT_SUICIDE_NONE("");
        }

        ques.setLOCK_CONDITION(lst_gszk.get(nice_spinner_gszk.getSelectedIndex()).getID());
        ques.setHOSPITALIZATI_STATUS(lst_zyqk.get(nice_spinner_zyqk.getSelectedIndex()).getID());

        String str_ed_time1_leave = ed_mccysj.getText().toString();
        if (!TextUtils.isEmpty(str_ed_time1_leave)) {
            try {
                ques.setLAST_LEAVE_HOSP_TIME((Date) dateFormat.parse(str_ed_time1_leave));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        ques.setLABOR_EXAMINATI(str_sysjcId);
        ques.setLABOR_EXAMINATI_HAVE(str_sysjcContent);
        ques.setMEDICATIO_COMPLIANCE(lst_fyycx.get(nice_spinner_fyycx.getSelectedIndex()).getID());
        ques.setADVER_DRU_REACT(str_ywblfyId);
        ques.setADVER_DRU_REACT_HAVE(str_ywblfyContent);
        ques.setTREATMENT_EFFECT(lst_zlxg.get(nice_spinner_zlxg.getSelectedIndex()).getID());
        ques.setWHETHER_REFERRAL(str_sfzzId);
        ques.setREFERRAL_REASON(str_sfzzContent);
        ques.setREFERRAL_AGENC_DEPAR(ed_zzzjgks.getText().toString());
        ques.setREHABILI_MEASU(str_kfcsId);
        ques.setREHABILI_MEASU_OTHER(str_kfcsContent);
        ques.setFOLLOWUP_CLASSIFICAT(lst_sffl.get(nice_spinner_sffl.getSelectedIndex()).getID());
        ques.setLAST_UPDATE_DATE(new Date());
        ques.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
        if (from_followup == 1) {

            ques.setUPDATEORG(userInfo.getCREATEORG());
            ques.setMODIFIED(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
            fdbmanger.updata(ques, "IDCARD='" + userInfo.getIDCARD() + "'");
        } else {
            ques.setCREATED_BY(userInfo.getCREATED_BY());
            ques.setCREATED_DATE(new Date());
            ques.setCREATEORG(userInfo.getCREATEORG());
            ques.setCREATER(userInfo.getCREATER());
            fdbmanger.save(ques);
            from_followup = 1;
        }
        // ((JSJBctivity) getActivity()).showTextDialog("保存成功");
        if (GlobalConts.TYPE_JTYS.equals(NovaApplication.getType())) {
            new AlertDialog.Builder(getActivity()).setTitle("保存成功").setMessage("进行满意度评价")
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(getContext(), FWMYDPJActivity.class);
                            intent.putExtra("type", "08");
                            intent.putExtra("szfs", "");
                            startActivity(intent);
                        }
                    }).show();
        } else if (GlobalConts.TYPE_GJJBGGWS.equals(NovaApplication.getType())) {
            ((JSJBctivity) getActivity()).showTextDialog("保存成功");
        }

    }

    private void saveDrug() {
        CD_DRUGCONDITION drug1 = new CD_DRUGCONDITION();
        drug1.setIDCARD(userInfo.getIDCARD());
        drug1.setTYPE("3");
        drug1.setNAME(ed_yw1.getText().toString());
        String str_daytimes = ed_yw1_mr.getText().toString();
        drug1.setDAILYTIME(str_daytimes);
        String str_mcjl = ed_yw1_mcjl.getText().toString();
        drug1.setEVERYTIMEMG(str_mcjl);
        drug1.setRES1(ywdw_list.get(nice_spinner_dw1.getSelectedIndex()).getID());

        CD_DRUGCONDITION drug2 = new CD_DRUGCONDITION();
        drug2.setIDCARD(userInfo.getIDCARD());
        drug2.setTYPE("3");
        drug2.setNAME(ed_yw2.getText().toString());
        String str_daytimes2 = ed_yw2_mr.getText().toString();
        drug2.setDAILYTIME(str_daytimes2);
        String str_mcjl2 = ed_yw2_mcjl.getText().toString();
        drug2.setEVERYTIMEMG(str_mcjl2);
        drug2.setRES1(ywdw_list.get(nice_spinner_dw1.getSelectedIndex()).getID());

        CD_DRUGCONDITION drug3 = new CD_DRUGCONDITION();
        drug3.setIDCARD(userInfo.getIDCARD());
        drug3.setTYPE("3");
        drug3.setNAME(ed_yw3.getText().toString());
        String str_daytimes3 = ed_yw3_mr.getText().toString();
        drug3.setDAILYTIME(str_daytimes3);
        String str_mcjl3 = ed_yw3_mcjl.getText().toString();
        drug3.setEVERYTIMEMG(str_mcjl3);
        drug3.setRES1(ywdw_list.get(nice_spinner_dw1.getSelectedIndex()).getID());

        CD_DRUGCONDITION drug4 = new CD_DRUGCONDITION();
        drug4.setIDCARD(userInfo.getIDCARD());
        drug4.setTYPE("6");
        drug4.setNAME(ed_ywzd1.getText().toString());
        String str_daytimes4 = ed_ywzd1_mr.getText().toString();
        drug4.setDAILYTIME(str_daytimes4);
        String str_mcjl4 = ed_ywzd1_mcjl.getText().toString();
        drug4.setEVERYTIMEMG(str_mcjl4);
        drug4.setRES1(ywdw_list.get(nice_spinner_dw1.getSelectedIndex()).getID());

        CD_DRUGCONDITION drug5 = new CD_DRUGCONDITION();
        drug5.setIDCARD(userInfo.getIDCARD());
        drug5.setTYPE("6");
        drug5.setNAME(ed_ywzd2.getText().toString());
        String str_daytimes5 = ed_ywzd2_mr.getText().toString();
        drug5.setDAILYTIME(str_daytimes5);
        String str_mcjl5 = ed_ywzd2_mcjl.getText().toString();
        drug5.setEVERYTIMEMG(str_mcjl5);
        drug5.setRES1(ywdw_list.get(nice_spinner_dw1.getSelectedIndex()).getID());

        CD_DRUGCONDITION drug6 = new CD_DRUGCONDITION();
        drug6.setIDCARD(userInfo.getIDCARD());
        drug6.setTYPE("6");
        drug6.setNAME(ed_ywzd3.getText().toString());
        String str_daytimes6 = ed_ywzd3_mr.getText().toString();
        drug6.setDAILYTIME(str_daytimes6);
        String str_mcjl6 = ed_ywzd3_mcjl.getText().toString();
        drug6.setEVERYTIMEMG(str_mcjl6);
        drug6.setRES1(ywdw_list.get(nice_spinner_dw1.getSelectedIndex()).getID());

        if (from_drug == 1) {
            if (drug_id1 != -1) {
                fdbmanger.updata(drug1, "IDCARD='" + userInfo.getIDCARD() + "' and type='3' and ID=" + drug_id1);
            } else {
                fdbmanger.save(drug1);
                from_drug = 1;
            }
            if (drug_id2 != -1) {
                fdbmanger.updata(drug2, "IDCARD='" + userInfo.getIDCARD() + "' and type='3' and ID=" + drug_id2);
            } else {
                fdbmanger.save(drug2);
                drug_id2 = 1;
            }
            if (drug_id3 != -1) {
                fdbmanger.updata(drug3, "IDCARD='" + userInfo.getIDCARD() + "' and type='3' and ID=" + drug_id3);
            } else {
                fdbmanger.save(drug3);
                drug_id3 = 1;
            }

        } else {
            fdbmanger.save(drug1);
            fdbmanger.save(drug2);
            fdbmanger.save(drug3);
        }
        if (from_drug2 == 1) {

            if (drug_id4 != -1) {
                Log.e("messss", drug4.toString());
                fdbmanger.updata(drug4, "IDCARD='" + userInfo.getIDCARD() + "' and type='6' and ID=" + drug_id4);// TODO
                // bug崩溃
            } else {
                fdbmanger.save(drug4);
                drug_id4 = 1;
            }
            if (drug_id5 != -1) {
                fdbmanger.updata(drug5, "IDCARD='" + userInfo.getIDCARD() + "' and type='6' and ID=" + drug_id5);
            } else {
                fdbmanger.save(drug5);
                drug_id5 = 1;
            }
            if (drug_id6 != -1) {
                fdbmanger.updata(drug6, "IDCARD='" + userInfo.getIDCARD() + "' and type='6' and ID=" + drug_id6);
            } else {
                fdbmanger.save(drug6);
                drug_id6 = 1;
            }

        } else {
            fdbmanger.save(drug4);
            fdbmanger.save(drug5);
            fdbmanger.save(drug6);
        }

    }

    /**
     * 设置 显示followup
     *
     * @author 王婷婷
     * @date 2015年12月24日 下午2:25:11
     */
    private void setData_followUP() {
        List<CD_MENTALDISEASE_FOLLOWUP> queses = fdbmanger.findAllByWhere(CD_MENTALDISEASE_FOLLOWUP.class,
                "IDCARD='" + userInfo.getIDCARD() + "'");
        int size = queses.size();
        if (size > 0) {
            from_followup = 1;

            ed_xm.setText(userInfo.getCUSTOMERNAME());
            ed_idcard.setText(userInfo.getIDCARD());
            CD_MENTALDISEASE_FOLLOWUP ques1 = queses.get(0);
            // 3.0新增字段
            int i = -1;
            if (!TextUtils.isEmpty(ques1.getFOLLOWUP_TYPE())) {// 本次随访形式 1 门诊 2
                // 家庭访视 3 电话
                i = -1;
                for (String str : bcsfxsids) {
                    i += 1;
                }
                rbsfxss.get(i).setChecked(true);
            }
            if (!TextUtils.isEmpty(ques1.getLossFollow())) {// 失访，原因 1 外出打工 2
                // 迁居他处 3 走失 4 连续 3
                // 次未到访 5 其他 □
                i = -1;
                for (String str : rsfyyIds) {
                    i += 1;
                    if (str.equals(ques1.getLossFollow())) {
                        break;
                    }
                }
                rbsfyys.get(i).setChecked(true);
            }
            if (!TextUtils.isEmpty(ques1.getLossFollow_EX())) {
                etsfqt.setText(ques1.getLossFollow_EX());
            } //
            if (null != ques1.getDeathDate()) {// 如果 死亡日期
                ed_swrq.setDate(ques1.getDeathDate());
            }
            if (!TextUtils.isEmpty(ques1.getDeathCause())) {// 如果 死亡原因
                i = -1;

                for (String str : swyyIds) {
                    i += 1;
                    if (str.equals(ques1.getDeathCause())) {
                        break;
                    }
                }
            }
            rbsws.get(i).setChecked(true);
            // if (!TextUtils.isEmpty(ques1.getDeathCauseBody())) {// 如果
            // 死亡原因中的躯体疾病
            // i=-1;
            // for(String str:swyyIds){
            // i+=1;
            // if(str.equals(ques1.getDeathCauseBody())){
            // break;
            // }
            // }
            // }

            if (!TextUtils.isEmpty(ques1.getDeathCause_EX())) {// 如果 死亡原因其他
                swqt.setText(ques1.getDeathCause_EX());
            }
            // ButterKnife8.8.1
            if (ques1.getNEXTFOLLOWUP_DATE() != null) {
                try {
                    ed_xcsfrq.setText(dateFormat.format(ques1.getNEXTFOLLOWUP_DATE()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            for (int i1 = 0; i1 < NovaApplication.getDoctorList().size(); i1++) {
                if (ques1.getFOLLOWUPDOCTOR().equals(NovaApplication.getDoctorList().get(i1).getUSER_ID())) {
                    ed_sfys.setSelectedIndex(i1);
                }
            }
            if (ques1.getFOLLOWUP_DATE() != null) {
                try {
                    ed_sfsj.setText(dateFormat.format(ques1.getFOLLOWUP_DATE()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            nice_spinner_wxx.setSelectedIndex(getListIndex(ques1.getFATALNESS(), lst_wxx));

            str_mqzzId = ques1.getPRESENT_SYMPTOM();
            str_mqzzContent = ques1.getPRESENT_SYMPTO_OTHER();
            adapter_mqzz.setChecked(str_mqzzId);
            adapter_mqzz.setOther(str_mqzzContent);

            nice_spinner_zzl.setSelectedIndex(getListIndex(ques1.getINSIGHT(), lst_zzl));

            nice_spinner_smqk.setSelectedIndex(getListIndex(ques1.getSLEEP_QUALITY(), lst_smqk));

            nice_spinner_ysqk.setSelectedIndex(getListIndex(ques1.getDIET(), lst_ysqk));
            nice_spinner_grshll.setSelectedIndex(getListIndex(ques1.getPERSONAL_CARE(), lst_grshll));
            nice_spinner_jwld.setSelectedIndex(getListIndex(ques1.getHOUSEWORK(), lst_jwld));

            nice_spinner_scldjgz.setSelectedIndex(getListIndex(ques1.getPRODUCT_LABOR_WORK(), lst_scldjgz));

            nice_spinner_xxnl.setSelectedIndex(getListIndex(ques1.getLEARNING_ABILITY(), lst_xxnl));

            nice_spinner_shrjjw.setSelectedIndex(getListIndex(ques1.getSOCIAL_INTER_INTERA(), lst_shrjjw));

            ed_sh_qdzs.setText(String.valueOf(ques1.getMILD_TROUBLE_FREQUEN()));

            ed_sh_zs.setText(String.valueOf(ques1.getCREATE_DISTU_FREQUEN()));
            ed_sh_zh.setText(String.valueOf(ques1.getCAUSE_ACCID_FREQUEN()));
            ed_sh_zs4.setText(String.valueOf(ques1.getAUTOLESION_FREQUEN()));
            ed_sh_zsws.setText(String.valueOf(ques1.getATTEMPT_SUIC_FREQUEN()));
            if (null != (ques1.getOtherDamage_FREQUEN())) {
                ed_sh_qtwhxw.setText(String.valueOf(ques1.getOtherDamage_FREQUEN()));
            }
            if ("null".equals(ques1.getATTEMPT_SUICIDE_NONE())) {
                cb_nothing.setChecked(true);
            } else if (TextUtils.isEmpty(ques1.getATTEMPT_SUICIDE_NONE())) {
                cb_nothing.setChecked(false);
            }
            nice_spinner_gszk.setSelectedIndex(getListIndex(ques1.getLOCK_CONDITION(), lst_gszk));

            nice_spinner_zyqk.setSelectedIndex(getListIndex(ques1.getHOSPITALIZATI_STATUS(), lst_zyqk));

            if (ques1.getLAST_LEAVE_HOSP_TIME() != null) {
                try {
                    ed_mccysj.setText(dateFormat.format(ques1.getLAST_LEAVE_HOSP_TIME()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            str_sfzzId = ques1.getWHETHER_REFERRAL();
            str_sfzzContent = ques1.getREFERRAL_REASON();
            adapter_sfzz.setChecked(str_sfzzId, str_sfzzContent);

            str_sysjcId = ques1.getLABOR_EXAMINATI();
            str_sysjcContent = ques1.getLABOR_EXAMINATI_HAVE();
            adapter_sysjc.setChecked(str_sysjcId, str_sysjcContent);

            str_ywblfyId = ques1.getADVER_DRU_REACT();
            str_ywblfyContent = ques1.getADVER_DRU_REACT_HAVE();
            adapter_ywblfy.setChecked(str_ywblfyId, str_ywblfyContent);
            if ("DM01-10_1".equals(str_sfzzId)) {
                rb_fou.setChecked(true);
            } else if ("DM01-10_2".equals(str_sfzzId)) {
                rb_shi.setChecked(true);
            }

            if ("DM01-11_1".equals(str_ywblfyId)) {
                rb_wu.setChecked(true);
            } else if ("DM01-11_2".equals(str_ywblfyId)) {
                rb_you.setChecked(true);
            } else if ("DM01-69_5".equals(str_ywblfyId)) {
                rb_xcbsy.setChecked(true);
            }
            et_you.setText(str_ywblfyContent);
            et_zzyy.setText(str_sfzzContent);
            nice_spinner_fyycx.setSelectedIndex(getListIndex(ques1.getMEDICATIO_COMPLIANCE(), lst_fyycx));

            nice_spinner_zlxg.setSelectedIndex(getListIndex(ques1.getTREATMENT_EFFECT(), lst_zlxg));

            ed_zzzjgks.setText(ques1.getREFERRAL_AGENC_DEPAR());
            str_kfcsId = ques1.getREHABILI_MEASU();
            adapter_kfcs.setChecked(str_kfcsId);
            str_kfcsContent = ques1.getREHABILI_MEASU_OTHER();
            adapter_kfcs.setOther(str_kfcsContent);
            nice_spinner_sffl.setSelectedIndex(getListIndex(ques1.getFOLLOWUP_CLASSIFICAT(), lst_sffl));

        } else {
            from_followup = 0;

            ed_xm.setText(userInfo.getCUSTOMERNAME());
            ed_sfsj.setText(dateFormat.format(new Date()));
            for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
                if (userInfo.getCREATED_BY().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
                    ed_sfys.setSelectedIndex(i);
                }

            }
            ed_idcard.setText(userInfo.getIDCARD());
        }
    }

    /**
     * 用药情况
     *
     * @author 王婷婷
     * @date 2015年12月24日 下午2:25:11
     */
    private void setData_drug() {
        List<CD_DRUGCONDITION> queses = fdbmanger.findAllByWhere(CD_DRUGCONDITION.class,
                "IDCARD='" + userInfo.getIDCARD() + "' and TYPE='3'");
        int size = queses.size();
        if (size > 0) {
            from_drug = 1;
            for (int i = 0; i < size; i++) {
                if (i == 0) {

                    CD_DRUGCONDITION ques1 = queses.get(0);
                    drug_id1 = ques1.getID();
                    ed_yw1.setText(ques1.getNAME());
                    ed_yw1_mr.setText(String.valueOf(ques1.getDAILYTIME()));
                    ed_yw1_mcjl.setText(String.valueOf(ques1.getEVERYTIMEMG()));
                    nice_spinner_dw1.setSelectedIndex(getListIndex(ques1.getRES1(), ywdw_list));

                } else if (i == 1) {
                    CD_DRUGCONDITION ques1 = queses.get(1);
                    drug_id2 = ques1.getID();
                    ed_yw2.setText(ques1.getNAME());
                    ed_yw2_mr.setText(String.valueOf(ques1.getDAILYTIME()));
                    ed_yw2_mcjl.setText(String.valueOf(ques1.getEVERYTIMEMG()));
                    nice_spinner_dw2.setSelectedIndex(getListIndex(ques1.getRES1(), ywdw_list));

                } else if (i == 2) {
                    CD_DRUGCONDITION ques1 = queses.get(2);
                    drug_id3 = ques1.getID();
                    ed_yw3.setText(ques1.getNAME());
                    ed_yw3_mr.setText(String.valueOf(ques1.getDAILYTIME()));
                    ed_yw3_mcjl.setText(String.valueOf(ques1.getEVERYTIMEMG()));
                    nice_spinner_dw3.setSelectedIndex(getListIndex(ques1.getRES1(), ywdw_list));

                }

            }

        } else {
            from_drug = 0;
        }
        ///////////////////////////////////////////
        List<CD_DRUGCONDITION> queses2 = fdbmanger.findAllByWhere(CD_DRUGCONDITION.class,
                "IDCARD='" + userInfo.getIDCARD() + "' and TYPE='6'");
        int size2 = queses2.size();
        if (size2 > 0) {
            from_drug2 = 1;
            for (int i = 0; i < size2; i++) {
                if (i == 0) {

                    CD_DRUGCONDITION ques1 = queses2.get(0);
                    drug_id4 = ques1.getID();
                    ed_ywzd1.setText(ques1.getNAME());
                    ed_ywzd1_mr.setText(String.valueOf(ques1.getDAILYTIME()));
                    ed_ywzd1_mcjl.setText(String.valueOf(ques1.getEVERYTIMEMG()));
                    nice_spinner_dw4.setSelectedIndex(getListIndex(ques1.getRES1(), ywdw_list));

                } else if (i == 1) {
                    CD_DRUGCONDITION ques1 = queses2.get(1);
                    drug_id5 = ques1.getID();
                    ed_ywzd2.setText(ques1.getNAME());
                    ed_ywzd2_mr.setText(String.valueOf(ques1.getDAILYTIME()));
                    ed_ywzd2_mcjl.setText(String.valueOf(ques1.getEVERYTIMEMG()));
                    nice_spinner_dw5.setSelectedIndex(getListIndex(ques1.getRES1(), ywdw_list));

                } else if (i == 2) {
                    CD_DRUGCONDITION ques1 = queses2.get(2);
                    drug_id6 = ques1.getID();
                    ed_ywzd3.setText(ques1.getNAME());
                    ed_ywzd3_mr.setText(String.valueOf(ques1.getDAILYTIME()));
                    ed_ywzd3_mcjl.setText(String.valueOf(ques1.getEVERYTIMEMG()));
                    nice_spinner_dw6.setSelectedIndex(getListIndex(ques1.getRES1(), ywdw_list));
                }
            }
        } else {
            from_drug2 = 0;
        }
    }

    private int getListIndex(String str, List<BD_DD_INFO> bds) {
        if (str != null && !str.equals("")) {

            for (int i = 0; i < bds.size(); i++) {
                if (str.equals(bds.get(i).getID())) {
                    return i;
                }
            }
        }
        return 0;
    }
}
